package com.gwcloud.leetcode.offers;

import com.gwcloud.leetcode.common.datastructure.TreeNode;

/** 
* @ClassName   : Leetcode0260 
* @author      : ganwei 
* @date        : 2020年6月2日 
* @Description : TODO 
*/
public class Leetcode0260 {
	/**
	 * -解题思路,思路同最高赞
	 */
    public boolean isSubStructure(TreeNode A, TreeNode B) {
    	return (A != null && B != null) && (isSame(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B));

    }
    
    /**
     * -判断两棵树是否为同一颗
     */
    public boolean isSame(TreeNode A, TreeNode B) {
    	if(A == null && B == null) {
    		return true;
    	}
    	
    	if(A == null && B != null) {
    		return false;
    	}
    	if(A != null && B == null) {
    		return false;
    	}
    	
    	if(A.val == B.val) {
    		return isSame(A.left, B.left) && isSame(A.right, B.right);
    	}
    	
    	return false;
    }
    
    /**
     * -主函数
     */
    public static void main(String[] args) {
    	
    }
}
